package com.yonyou.cyxdms.basedata.service.controller.region;

import com.yonyou.cyxdms.basedata.client.domains.vo.RegionVO;
import com.yonyou.cyxdms.basedata.client.dto.RegionConditionDTO;
import com.yonyou.cyxdms.basedata.service.entity.region.RegionPO;
import com.yonyou.cyxdms.basedata.service.service.region.RegionService;
import com.yonyou.cyxdms.basedata.service.vo.region.AllRegionVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 省市区县
 *
 * @author renwd
 * @since 2018/12/19
 */

@RestController
@RequestMapping("/region")
public class RegionController {

    @Autowired
    private RegionService regionService;

    /**
     * 查询所有省份
     *
     * @param
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @author renwd
     * @since 2018/12/19
     */
    @GetMapping("/listAllProvice")
    public List<RegionPO> listAllProvice() {
        return regionService.listAllProvice();
    }

    /**
     * 根据id查询省/市信息
     *
     * @param id 省id
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @author renwd
     * @since 2018/12/19
     */
    @GetMapping("/listCityByProviceId/{id}")
    public List<RegionPO> listDataById(@PathVariable("id") Long id) {
        return regionService.listDataById(id);
    }

    /**
     * 查询所有省市区县信息
     *
     * @param
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @author renwd
     * @since 2018/12/27
     */
    @GetMapping("/listAllRegionData")
    public List<AllRegionVO> listAllRegionData() {
        return regionService.listAllRegionData();
    }

    /**
     * 查询所有省市区数据
     *
     * @param
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.region.RegionVO>
     * @author renwd
     * @since 2019/7/12
     */
    @GetMapping("/listAllData")
    public List<RegionVO> listAllData() {
        return regionService.listAllData();
    }

    /**
     * 查询所有省市区数据
     *
     * @param
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.region.RegionVO>
     * @author renwd
     * @since 2019/7/12
     */
    @GetMapping("/listAllDataByAppId")
    public List<RegionVO> listAllDataByAppId(@RequestParam("appId") String appId) {
        return regionService.listAllDataByAppId(appId);
    }

    /**
     * 根据type查询省市区
     *
     * @param regionCode
     * @return java.util.List<com.yonyou.cyxdms.basedata.service.vo.region.RegionVO>
     * @author renwd
     * @since 2019/7/12
     */
    @GetMapping("/listAllDataByType")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", required = true, dataType = "string", paramType = "header")
    })
    public List<RegionVO> listAllDataByType(@RequestParam("regionCode") String regionCode) {
        return regionService.listAllDataByType(regionCode);
    }

    /**
     * 省市映射
     *
     * @param provinceName
     * @param cityName
     * @return java.util.Map<java.lang.String, java.lang.Long>
     * @author tanjie
     * @since 2019/9/10
     */
    @GetMapping("/getRegion")
    public Map<String, Long> getRegion(@RequestParam("provinceName") String provinceName,
                                       @RequestParam("cityName") String cityName) {
        return regionService.getRegion(provinceName, cityName);
    }

    @GetMapping("/getProvinceRelatedData")
    public List<RegionVO> getProvinceRelatedData(@RequestParam("ids") List<Long> ids) {
        return this.regionService.getProvinceRelatedData(ids);
    }


    /**
     * 通用根据城市名称查询省市区ID列表
     *
     * @param
     * @return java.util.List<java.lang.Long>
     * @author dengqiang
     * @since 2019/10/31
     */
    @PostMapping("/getRegionIdList")
    public List<Long> getRegionIdList(@RequestBody RegionConditionDTO regionConditionDTO) {
        return regionService.getRegionIdList(regionConditionDTO);
    }

    /**
     * 根据名称获取对应ID
     *
     * @param:
     * @return:
     * @auther: tanjie
     * @since: 2019/11/4
     */
    @GetMapping("/mappingRegionName")
    public RegionVO mappingRegionName(@RequestParam("regionType") Integer regionType,
                                      @RequestParam("regionName") String regionName,
                                      @RequestParam(value = "appId") String appId,
                                      @RequestParam(value = "parentRegionId", required = false) Long parentId) {
        return this.regionService.mappingRegionName(regionType, regionName, appId, parentId);
    }

    /**
     * id查region
     *
     * @param:
     * @return:
     * @auther: tanjie
     * @since: 2019/11/4
     */
    @GetMapping("/getRegionById")
    public RegionVO getRegionById(@RequestParam("id") Long id) {
        return this.regionService.getRegionById(id);
    }


    /**
     * CODE查region
     *
     * @param:
     * @return:
     * @auther: tanjie
     * @since: 2019/11/4
     */
    @GetMapping("/getRegionByCode")
    public RegionVO getRegionByCode(@RequestParam("code") String code, @RequestParam("appId") String appId) {
        return this.regionService.getRegionByCode(code, appId);
    }

    /**
     * CODE查region
     *
     * @param appid
     * @return:
     * @auther: tanjie
     * @since: 2019/11/4
     */
    @GetMapping("/getAllRegion")
    public List<RegionVO> getAllRegion(@RequestParam("appId") String appid) {
        return this.regionService.getAllRegion(appid);
    }
}

